// package: learn-go
// filename: gorountine_other_mode
// author: Administrator@gmail.com
// time: 2023/8/21 10:49

package gorountine_other_mode

import (
	"fmt"
	"time"
)

// Task 接口对象
type Task interface {
	Execute(duration time.Duration)
}

var _ Task = &task{}

type task struct {
	id          int
	status      string
	executeTime time.Duration
}

func newTask(id int) *task {
	return &task{id: id, status: "unrun"}
}

func (t *task) Execute(duration time.Duration) {
	t.executeTime = duration
	t.status = "running"
	time.Sleep(duration)
	fmt.Println("task ", t.id, "is finished")
	t.status = "finished"
}
